<template>
	<view class="login-wrapper">
		<view class="head-wrapper">
			<view class="fh">
				<u-icon name="arrow-left" color="white" size="20" @click="fh()"></u-icon>
			</view>
			<view class="conten">
				<view class="title">绑定手机号</view> <br>

				<u-input placeholder="请输入手机号" v-model="phone" maxlength="11"></u-input>
				<u-input placeholder="请输入验证码" v-model="code">
					<template slot="suffix">
						<u-code ref="uCode" @change="codeChange" seconds="20" changeText="X秒重新获取哈哈哈"></u-code>
						<u-button @tap="getCode" :text="tips" type="success" size="mini"></u-button>
					</template>
				</u-input>

				<view class="btn" @click="bindbtn()">绑定</view>
			</view>
		</view>

		<!-- 消息提示 -->
		<u-toast ref="uToast"></u-toast>
		<u-cell-group title-bg-color="rgb(243, 244, 246)">
			<u-cell :titleStyle="{fontWeight: 500}" :title="item.title" v-for="(item, index) in list" :key="index"
				isLink :icon="item.iconUrl" @click="showToast(item)">
			</u-cell>
		</u-cell-group>

	</view>
</template>

<script>
	import {
		capList, //发送验证码
		bindList //绑定手机号
	} from "../api/login.js"
	export default {
		data() {
			return {
				phone: "", //手机号
				code: "", //验证码
				tips: '发送验证码',
				value: '',
				visiable: false,
				obj: {
					password: "",
					repassword: "",
					username: "",
				},

			}
		},
		methods: {
			codeChange(text) {
				this.tips = text;
			},
			//返回上一级
			fh() {
				uni.navigateBack({
					delta: 1
				})
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})

					setTimeout(async () => {
						uni.hideLoading();
						const res = await capList({
							phone: this.phone
						})
						console.log(res, "验证码")
						// 这里此提示会被this.start()方法中的提示覆盖
						uni.$u.toast('验证码已发送' + res.data.data);
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					}, 2000);
				} else {
					uni.$u.toast('倒计时结束后再发送');
				}
			},
			change(e) {
				console.log('change', e);
			},


			//登录
			async bindbtn() {
				const res = await bindList({
					code: this.code,
					phone: this.phone
				})
				if (res.data.msg == "ok") {
					this.$refs.uToast.show({
						type: 'default',
						message: res.data.data,
					})
					uni.navigateBack({
						delta: 1
					})
				}
				console.log(res, "验证码")
			}
		}
	}
</script>

<style lang="scss">
	.login-wrapper {
		width: 100%;
		height: 100%;
		overflow: hidden;
		background-image: linear-gradient(120deg, #3bfdaf, #70d6f2);

		.head-wrapper {
			width: 100%;
			height: 250rpx;
			background-image: linear-gradient(120deg, #3bfdaf, #70d6f2);

			.fh {
				margin-top: 60rpx;
				box-sizing: border-box;
				height: 80rpx;
				display: flex;
				align-items: center;
				padding-left: 40rpx;
			}
		}

		.conten {
			width: 100%;
			height: 100%;
			position: absolute;
			top: 204rpx;
			left: 0;
			right: 0;
			background-color: #fff;
			border-top-left-radius: 100rpx;
			border-top-right-radius: 100rpx;
			padding: 61rpx 71rpx 0 71rpx;
			box-sizing: border-box;


			.name {
				margin-top: 30rpx;
				margin-bottom: 30rpx;
				border-radius: 5rpx;
				padding-left: 20rpx;
				height: 80rpx;
				font-size: 30rpx;
				background-color: gainsboro;
			}

			.u-input {
				margin-top: 30rpx;
			}

			.yue {
				margin-top: 30rpx;
				height: 90rpx;
				width: 100%;
				font-size: 30rpx;
				color: #a9a5a0;
				display: flex;
				justify-content: center;
				align-items: center;
			}

			.zhu {
				margin-top: 40rpx;
				height: 90rpx;
				width: 100%;
				border-radius: 10rpx;
				font-size: 30rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				color: #5ccc84;

				.wj {
					color: #a9a5a0;
				}
			}

			.btn {
				margin-top: 20rpx;
				height: 90rpx;
				width: 100%;
				border-radius: 10rpx;
				font-size: 33rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				color: white;
				background-color: #5ccc84;
			}

			.title {
				font-size: 35rpx;
			}

			.u--input {
				background-color: #3bfdaf;
			}
		}
	}
</style>
